package com.power.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.power.domain.Prod;
import com.power.model.Result;
import com.power.service.SearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description 搜索业务控制层
 * @Author dingchunlin
 * @Date 2024/07/21 16:45
 * @Version 1.0.0
 */
@Api(tags = "搜索业务接口管理")
@RestController
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 根据分组标签分页查询商品信息
     * @param current 页码
     * @param size 每页显示的页数
     * @param tagId 分组标签ID
     * @return 分页商品信息
     */
    @ApiOperation(value = "根据分组标签分页查询商品信息")
    @GetMapping("/prod/prodListByTagId")
    public Result<Page<Prod>> loadWxProdListByTagId(@RequestParam(defaultValue = "1") Long current,
                                                     @RequestParam Long size,
                                                     @RequestParam Long tagId) {
        Page<Prod> page = searchService.queryWxProdListByTagId(current, size, tagId);
        return Result.success(page);
    }

    /**
     * 根据分类ID分页查询商品信息
     * @param categoryId 分类ID
     * @return 分页商品信息
     */
    @ApiOperation(value = "微信小程序端根据分类ID分页查询商品信息")
    @GetMapping("/prod/category/prod/list")
    public Result<List<Prod>> loadProdListByCategoryId(@RequestParam Long categoryId) {
        List<Prod> prodList = searchService.queryWxProdListByCategoryId(categoryId);
        return Result.success(prodList);
    }
}
